// [3392]-统计符合条件长度为 3 的子数组数目
struct Solution;

//leetcode submit region begin(Prohibit modification and deletion)
impl Solution {
    pub fn count_subarrays(nums: Vec<i32>) -> i32 {
        let mut result = 0;
        let mut index = 0;
        while nums.len() - index >= 3 {
            if 2 * (nums[index] + nums[index + 2]) == nums[index + 1] {
                result += 1;
            }
            index += 1;
        }
        result
    }
}
//leetcode submit region end(Prohibit modification and deletion)

#[test]
fn main() {
    let nums = vec![1, 2, 1, 4, 1];
    assert_eq!(Solution::count_subarrays(nums), 1);
    let nums = vec![1, 1, 1];
    assert_eq!(Solution::count_subarrays(nums), 0);
}
